<template>
	<view class="page company">
		<form>
			<view class="cu-form-group">
				<view class="title">企业名称</view>
				<input placeholder="请输入企业名称" @blur="handleBlur" v-model="formData.name"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">统一社会信用代码</view>
				<input placeholder="请输入统一社会信用代码" v-model="formData.code"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">实际经营地址</view>
				<input placeholder="请输入实际经营地址" v-model="formData.house_address"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">注册地址</view>
				<input placeholder="请输入注册地址" v-model="formData.registered_address"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">员工规模</view>
				<input placeholder="请输入员工规模" v-model="formData.people_number"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">公司类型</view>
				<input placeholder="请输入公司类型" v-model="formData.type"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">所属行业</view>
				<input placeholder="请输入所属行业" v-model="formData.industry"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">行业标签</view>
				<input placeholder="请输入行业标签" v-model="formData.industry_label"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">经营范围</view>
				<input placeholder="请输入经营范围" v-model="formData.business_scope"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">登记机关</view>
				<input placeholder="请输入登记机关" v-model="formData.registration_authority"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">所属街道</view>
				<input placeholder="请输入所属街道" v-model="formData.registered_address"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">入驻类型</view>
				<input placeholder="请输入入驻类型" v-model="formData.type"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">租用楼层</view>
				<input placeholder="请输入租用楼层"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">租用房间号</view>
				<input placeholder="请输入租用房间号"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">租用面积</view>
				<input placeholder="请输入租用面积"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">是否本区注册企业</view>
				<input placeholder="请输入是否本区注册企业"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">是否本区纳税企业</view>
				<input placeholder="请输入是否本区纳税企业"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">是总部</view>
				<view style="display: flex;">
					<label class="radio" style="margin: auto 50px;">
						<radio style="margin-right: 10px;" :checked="formData.head_office == 1"
							@click="isSelected(1, 'head_office')" />是
					</label>
					<label class="radio">
						<radio style="margin-right: 10px;" :checked="formData.head_office == 2"
							@click="isSelected(2, 'head_office')" />否
					</label>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">法人代表姓名</view>
				<input placeholder="请输入法人" v-model="formData.legal_person"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">法人联系方式</view>
				<input placeholder="请输入法人联系方式" type="number" v-model="formData.legal_person_mobile"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">法人证件类型</view>
				<view class="uni-list-cell-db">
					<picker @change="bindPickerChange" :value="formData.legal_person_certificate_type - 1"
						:range="array">
						<view class="uni-input">{{array[formData.legal_person_certificate_type - 1]}}</view>
					</picker>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">法人证件号</view>
				<input placeholder="请输入法人证件号" type="number" v-model="formData.legal_person_certificate_code"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">法人国籍</view>
				<input placeholder="请输入法人国籍" v-model="formData.legal_person_nationality"></input>
			</view>
			<view class="padding">
				<button @click="createEnterpriseFun" class="cu-btn block bg-blue margin-tb-sm lg">
					创建企业
				</button>
			</view>
		</form>
	</view>
</template>

<script>
	import getUrlParams from '@/utils/getUrlParams.js';
	import Autocomplete from '@/components/autocomplete';
	import {
		createEnterprise
	} from '../../api/enterprise.js'
	export default {
		components:{
			Autocomplete
		},
		data() {
			return {
				formData: {
					building_id: '',
					region_id: '',
					name: "",
					code: "",
					house_address: "",
					is_registered: 1,
					registered_address_status: 1,
					registered_address: "",
					people_number: "",
					type: "",
					industry: "",
					industry_label: "",
					business_scope: "",
					registration_authority: "",
					approve_time: null,
					head_office: 1,
					business_license: "",
					legal_person: null,
					legal_person_mobile: null,
					legal_person_certificate_type: 1,
					legal_person_certificate_code: null,
					legal_person_status: 1,
					legal_person_nationality: null,
				},
				array: ['身份证', '护照', '驾照']
			}
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo;
			},
			isLogin() {
				if (this.$store.state.token) {
					return true;
				} else {
					return false;
				}
			},
		},
		onLoad(query) {
			console.log("参数", query)
			if (this.isLogin) {
				if (query && query.q) {
					let data = getUrlParams(decodeURIComponent(query.q));
					this.formData['building_id'] = data.building_id;
					this.formData['region_id'] = data.region_id;
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			} else {
				this.$route("pages/login/login")
			}
		},
		methods: {
			/**
			 * 处理失焦
			 */
			handleBlur() {

			},
			/**
			 * @param {Object} bool
			 * @param {Object} key
			 */
			isSelected(bool, key) {
				this.formData[key] = bool
			},
			bindPickerChange(e) {
				this.formData.legal_person_certificate_type = Number(e.detail.value) + 1
			},
			createEnterpriseFun() {
				createEnterprise(this.formData).then(res => {
					console.log(res)
					uni.showToast({
						title: '认证成功',
						duration: 2000
					});
					uni.switchTab({
						url: '/pages/my/my'
					})
				})
			}
		}
	}
</script>

<style>

</style>
